home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cc / sprite / final.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  42.0 KB  |  1,613 lines

  1. /* Convert RTL to assembler code and output it, for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This is the final pass of the compiler.
  22.    It looks at the rtl code for a function and outputs assembler code.
  23.  
  24.    Call `final_start_function' to output the assembler code for function entry,
  25.    `final' to output assembler code for some RTL code,
  26.    `final_end_function' to output assembler code for function exit.
  27.    If a function is compiled in several pieces, each piece is
  28.    output separately with `final'.
  29.  
  30.    Some optimizations are also done at this level.
  31.    Move instructions that were made unnecessary by good register allocation
  32.    are detected and omitted from the output.  (Though most of these
  33.    are removed by the last jump pass.)
  34.  
  35.    Instructions to set the condition codes are omitted when it can be
  36.    seen that the condition codes already had the desired values.
  37.  
  38.    In some cases it is sufficient if the inherited condition codes
  39.    have related values, but this may require the following insn
  40.    (the one that tests the condition codes) to be modified.
  41.  
  42.    The code for the function prologue and epilogue are generated
  43.    directly as assembler code by the macros FUNCTION_PROLOGUE and
  44.    FUNCTION_EPILOGUE.  Those instructions never exist as rtl.  */
  45.  
  46. #include <stdio.h>
  47. #include "config.h"
  48. #include "rtl.h"
  49. #include "regs.h"
  50. #include "insn-config.h"
  51. #include "recog.h"
  52. #include "conditions.h"
  53. #include "gdbfiles.h"
  54. #include "flags.h"
  55. #include "real.h"
  56. #include "output.h"
  57.  
  58. /* Get N_SLINE and N_SOL from stab.h if we can expect the file to exist.  */
  59. #ifdef DBX_DEBUGGING_INFO
  60. #ifdef USG
  61. #include "stab.h"  /* If doing DBX on sysV, use our own stab.h.  */
  62. #else
  63. #include <stab.h>  /* On BSD, use the system's stab.h.  */
  64. #endif /* not USG */
  65. #endif /* DBX_DEBUGGING_INFO */
  66.  
  67. /* .stabd code for line number.  */
  68. #ifndef N_SLINE
  69. #define    N_SLINE    0x44
  70. #endif
  71.  
  72. /* .stabs code for included file name.  */
  73. #ifndef N_SOL
  74. #define    N_SOL 0x84
  75. #endif
  76.  
  77. #define min(A,B) ((A) < (B) ? (A) : (B))
  78.  
  79. rtx peephole ();
  80. void output_asm_insn ();
  81. rtx alter_subreg ();
  82. static int alter_cond ();
  83. void output_asm_label ();
  84. static void output_operand ();
  85. void output_address ();
  86. void output_addr_const ();
  87. static void output_source_line ();
  88. rtx final_scan_insn ();
  89.  
  90. /* the sdb debugger needs the line given as an offset from the beginning
  91.    of the current function -wfs*/
  92.  
  93. extern int sdb_begin_function_line;
  94.  
  95. /* Line number of last NOTE.  */
  96. static int last_linenum;
  97.  
  98. /* Number of basic blocks seen so far;
  99.    used if profile_block_flag is set.  */
  100. static int count_basic_blocks;
  101.  
  102. /* Nonzero while outputting an `asm' with operands.
  103.    This means that inconsistencies are the user's fault, so don't abort.
  104.    The precise value is the insn being output, to pass to error_for_asm.  */
  105. static rtx this_is_asm_operands;
  106.  
  107. /* Number of operands of this insn, for an `asm' with operands.  */
  108. static int insn_noperands;
  109.  
  110. /* File in which assembler code is being written.  */
  111.  
  112. extern FILE *asm_out_file;
  113.  
  114. /* Compare optimization flag. */
  115.  
  116. static rtx last_ignored_compare = 0;
  117.  
  118. /* Flag indicating this insn is the start of a new basic block. */
  119.  
  120. static int new_block = 1;
  121.  
  122. /* All the symbol-blocks (levels of scoping) in the compilation
  123.    are assigned sequence numbers in order of appearance of the
  124.    beginnings of the symbol-blocks.  Both final and dbxout do this,
  125.    and assume that they will both give the same number to each block.
  126.    Final uses these sequence numbers to generate assembler label names
  127.    LBBnnn and LBEnnn for the beginning and end of the symbol-block.
  128.    Dbxout uses the sequence nunbers to generate references to the same labels
  129.    from the dbx debugging information.
  130.  
  131.    Sdb records this level at the beginning
  132.    of each function, so that when it recurses down the declarations, it may
  133.    find the current level, since it outputs the block beginning and endings
  134.    at the point in the asm file, where the blocks would begin and end.  */
  135.  
  136. int next_block_index;
  137.  
  138. /* Chain of all `struct gdbfile's.  */
  139.  
  140. struct gdbfile *gdbfiles;
  141.  
  142. /* `struct gdbfile' for the last file we wrote a line number for.  */
  143.  
  144. static struct gdbfile *current_gdbfile;
  145.  
  146. /* Filenum to assign to the next distinct source file encountered.  */
  147.  
  148. static int next_gdb_filenum;
  149.  
  150. /* This variable contains machine-dependent flags (defined in tm-...h)
  151.    set and examined by output routines
  152.    that describe how to interpret the condition codes properly.  */
  153.  
  154. CC_STATUS cc_status;
  155.  
  156. /* During output of an insn, this contains a copy of cc_status
  157.    from before the insn.  */
  158.  
  159. CC_STATUS cc_prev_status;
  160.  
  161. /* Last source file name mentioned in a NOTE insn.  */
  162.  
  163. static char *lastfile;
  164.  
  165. /* Indexed by hardware reg number, is 1 if that register is ever
  166.    used in the current function.
  167.  
  168.    In life_analysis, or in stupid_life_analysis, this is set
  169.    up to record the hard regs used explicitly.  Reload adds
  170.    in the hard regs used for holding pseudo regs.  Final uses
  171.    it to generate the code in the function prologue and epilogue
  172.    to save and restore registers as needed.  */
  173.  
  174. char regs_ever_live[FIRST_PSEUDO_REGISTER];
  175.  
  176. /* Nonzero means current function must be given a frame pointer.
  177.    Set in stmt.c if anything is allocated on the stack there.
  178.    Set in reload1.c if anything is allocated on the stack there.  */
  179.  
  180. int frame_pointer_needed;
  181.  
  182. /* Assign unique numbers to labels generated for profiling.  */
  183.  
  184. int profile_label_no;
  185.  
  186. /* Length so far allocated in PENDING_BLOCKS.  */
  187.  
  188. static int max_block_depth;
  189.  
  190. /* Stack of sequence numbers of symbol-blocks of which we have seen the
  191.    beginning but not yet the end.  Sequence numbers are assigned at
  192.    the beginning; this stack allows us to find the sequence number
  193.    of a block that is ending.  */
  194.  
  195. static int *pending_blocks;
  196.  
  197. /* Number of elements currently in use in PENDING_BLOCKS.  */
  198.  
  199. static int block_depth;
  200.  
  201. /* Nonzero if have enabled APP processing of our assembler output.  */
  202.  
  203. static int app_on;
  204.  
  205. /* If we are outputting an insn sequence, this contains the sequence rtx.
  206.    Zero otherwise.  */
  207.  
  208. rtx final_sequence;
  209.  
  210. /* Initialize data in final at the beginning of a compilation.  */
  211.  
  212. void
  213. init_final (filename)
  214.      char *filename;
  215. {
  216.   next_block_index = 2;
  217.   lastfile = filename;
  218.   app_on = 0;
  219.   max_block_depth = 20;
  220.   pending_blocks = (int *) xmalloc (20 * sizeof *pending_blocks);
  221.   gdbfiles = 0;
  222.   next_gdb_filenum = 0;
  223.   final_sequence = 0;
  224. }
  225.  
  226. /* Called at end of source file,
  227.    to output the block-profiling table for this entire compilation.  */
  228.  
  229. void
  230. end_final (filename)
  231.      char *filename;
  232. {
  233.   int i;
  234.  
  235.   if (profile_block_flag)
  236.     {
  237.       char name[12];
  238.  
  239.       data_section ();
  240.  
  241.       /* Output the main header, of 6 words:
  242.      0:  1 if this file's initialized, else 0.
  243.      1:  address of file name.
  244.      2:  address of table of counts.
  245.      4:  number of counts in the table.
  246.      5:  always 0, for compatibility with Sun.
  247.      6:  extra word added by GNU: address of address table
  248.           which contains addresses of basic blocks,
  249.           in parallel with the table of counts.  */
  250.       ASM_OUTPUT_ALIGN (asm_out_file,
  251.             exact_log2 (min (UNITS_PER_WORD,
  252.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  253.  
  254.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 0);
  255.       assemble_integer_zero ();
  256.  
  257.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 1);
  258.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  259.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 2);
  260.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  261.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (CONST_INT, VOIDmode,
  262.                          count_basic_blocks));
  263.       assemble_integer_zero ();
  264.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  265.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  266.  
  267.       /* Output the file name.  */
  268.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 1);
  269.       assemble_string (filename, strlen (filename) + 1);
  270.  
  271.       /* Realign data section.  */
  272.       ASM_OUTPUT_ALIGN (asm_out_file,
  273.             exact_log2 (min (UNITS_PER_WORD,
  274.                      BIGGEST_ALIGNMENT / BITS_PER_UNIT)));
  275.  
  276.       /* Make space for the table of counts.  */
  277.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 2);
  278.       ASM_OUTPUT_SKIP (asm_out_file, UNITS_PER_WORD * count_basic_blocks);
  279.  
  280.       /* Output the table of addresses.  */
  281.       text_section ();
  282.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LPBX", 3);
  283.       for (i = 0; i < count_basic_blocks; i++)
  284.     {
  285.       char name[12];
  286.       ASM_GENERATE_INTERNAL_LABEL (name, "LPB", i);
  287.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  288.     }
  289.  
  290.       /* End with the address of the table of addresses,
  291.      so we can find it easily, as the last word in the file's text.  */
  292.       ASM_GENERATE_INTERNAL_LABEL (name, "LPBX", 3);
  293.       ASM_OUTPUT_INT (asm_out_file, gen_rtx (SYMBOL_REF, Pmode, name));
  294.     }
  295. }
  296.  
  297. /* Enable APP processing of subsequent output.
  298.    Used before the output from an `asm' statement.  */
  299.  
  300. void
  301. app_enable ()
  302. {
  303.   if (! app_on)
  304.     {
  305.       fprintf (asm_out_file, ASM_APP_ON);
  306.       app_on = 1;
  307.     }
  308. }
  309.  
  310. /* Enable APP processing of subsequent output.
  311.    Called from varasm.c before most kinds of output.  */
  312.  
  313. void
  314. app_disable ()
  315. {
  316.   if (app_on)
  317.     {
  318.       fprintf (asm_out_file, ASM_APP_OFF);
  319.       app_on = 0;
  320.     }
  321. }
  322.  
  323. /* Return the number of slots filled in the current 
  324.    delayed branch sequence. */
  325.  
  326. #ifdef HAVE_DELAYED_BRANCH
  327. int
  328. dbr_sequence_length ()
  329. {
  330.   int i;
  331.   int slots = 0;
  332.   /* It's zero if we are not scheduling or not in a sequence. 
  333.      (We never count the first insn.)                  */
  334.   if (flag_delayed_branch && final_sequence != 0)
  335.     {
  336.       for (i = 1; i < XVECLEN (final_sequence, 0); i++)
  337.     slots += DBR_INSN_SLOTS (XVECEXP (final_sequence, 0, i));
  338.     }
  339.   return slots;
  340. }
  341. #endif
  342.  
  343. /* Output assembler code for the start of a function,
  344.    and initialize some of the variables in this file
  345.    for the new function.  The label for the function and associated
  346.    assembler pseudo-ops have already been output in `assemble_function'.
  347.  
  348.    FIRST is the first insn of the rtl for the function being compiled.
  349.    FILE is the file to write assembler code to.
  350.    WRITE_SYMBOLS says which kind of debugging info to write (or none).
  351.    OPTIMIZE is nonzero if we should eliminate redundant
  352.      test and compare insns.  */
  353.  
  354. void
  355. final_start_function (first, file, write_symbols, optimize)
  356.      rtx first;
  357.      FILE *file;
  358.      enum debugger write_symbols;
  359.      int optimize;
  360. {
  361.   block_depth = 0;
  362.  
  363.   this_is_asm_operands = 0;
  364.  
  365.   /* Record beginning of the symbol-block that's the entire function.  */
  366.  
  367.   if (write_symbols == GDB_DEBUG)
  368.     {
  369.       pending_blocks[block_depth++] = next_block_index;
  370.       fprintf (file, "\t.gdbbeg %d\n", next_block_index++);
  371.     }
  372.  
  373.   /* Initial line number is supposed to be output
  374.      before the function's prologue and label
  375.      so that the function's address will not appear to be
  376.      in the last statement of the preceding function.  */
  377.   if (NOTE_LINE_NUMBER (first) != NOTE_INSN_DELETED)
  378.     output_source_line (file, first, write_symbols);
  379.  
  380. #ifdef FUNCTION_PROLOGUE
  381.   /* First output the function prologue: code to set up the stack frame.  */
  382.   FUNCTION_PROLOGUE (file, get_frame_size ());
  383. #endif
  384.  
  385. #ifdef SDB_DEBUGGING_INFO
  386.   next_block_index = 1;
  387. #endif
  388.  
  389. #ifdef FUNCTION_BLOCK_PROFILER
  390.   if (profile_block_flag)
  391.     {
  392.       FUNCTION_BLOCK_PROFILER (file, profile_label_no);
  393.     }
  394. #endif /* FUNCTION_BLOCK_PROFILER */
  395.  
  396.   if (profile_flag)
  397.     {
  398.       int align = min (BIGGEST_ALIGNMENT, BITS_PER_WORD);
  399.       extern int current_function_returns_struct;
  400.       extern int current_function_needs_context;
  401.       int sval = current_function_returns_struct;
  402.       int cxt = current_function_needs_context;
  403.  
  404. #ifndef sprite      
  405.       data_section ();
  406.       ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
  407.       ASM_OUTPUT_INTERNAL_LABEL (file, "LP", profile_label_no);
  408.       assemble_integer_zero ();
  409.  
  410.       text_section ();
  411.  
  412. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  413.       if (sval)
  414.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_INCOMING_REGNUM);
  415. #else
  416. #ifdef STRUCT_VALUE_REGNUM
  417.       if (sval)
  418.     ASM_OUTPUT_REG_PUSH (file, STRUCT_VALUE_REGNUM);
  419. #endif
  420. #endif
  421.  
  422. #if 0
  423. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  424.       if (cxt)
  425.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_INCOMING_REGNUM);
  426. #else
  427. #ifdef STATIC_CHAIN_REGNUM
  428.       if (cxt)
  429.     ASM_OUTPUT_REG_PUSH (file, STATIC_CHAIN_REGNUM);
  430. #endif
  431. #endif
  432. #endif /* 0 */
  433. #endif
  434.  
  435.       FUNCTION_PROFILER (file, profile_label_no);
  436.  
  437. #if 0
  438. #ifdef STATIC_CHAIN_INCOMING_REGNUM
  439.       if (cxt)
  440.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_INCOMING_REGNUM);
  441. #else
  442. #ifdef STATIC_CHAIN_REGNUM
  443.       if (cxt)
  444.     ASM_OUTPUT_REG_POP (file, STATIC_CHAIN_REGNUM);
  445. #endif
  446. #endif
  447. #endif /* 0 */
  448.  
  449. #ifndef sprite      
  450. #ifdef STRUCT_VALUE_INCOMING_REGNUM
  451.       if (sval)
  452.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_INCOMING_REGNUM);
  453. #else
  454. #ifdef STRUCT_VALUE_REGNUM
  455.       if (sval)
  456.     ASM_OUTPUT_REG_POP (file, STRUCT_VALUE_REGNUM);
  457. #endif
  458. #endif
  459. #endif      
  460.     }
  461.  
  462.   profile_label_no++;
  463. }
  464.  
  465. /* Output assembler code for the end of a function.
  466.    For clarity, args are same as those of `final_start_function'
  467.    even though not all of them are needed.  */
  468.  
  469. void
  470. final_end_function (first, file, write_symbols, optimize)
  471.      rtx first;
  472.      FILE *file;
  473.      enum debugger write_symbols;
  474.      int optimize;
  475. {
  476.   if (app_on)
  477.     {
  478.       fprintf (file, ASM_APP_OFF);
  479.       app_on = 0;
  480.     }
  481.  
  482.   if (write_symbols == GDB_DEBUG)
  483.     fprintf (file, "\t.gdbend %d\n", pending_blocks[0]);
  484.  
  485. #ifdef SDB_DEBUGGING_INFO
  486.   if (write_symbols == SDB_DEBUG)
  487.     sdbout_end_function (last_linenum);
  488. #endif
  489.  
  490. #ifdef FUNCTION_EPILOGUE
  491.   /* Finally, output the function epilogue:
  492.      code to restore the stack frame and return to the caller.  */
  493.   FUNCTION_EPILOGUE (file, get_frame_size ());
  494. #endif
  495.  
  496. #ifdef SDB_DEBUGGING_INFO
  497.   if (write_symbols == SDB_DEBUG)
  498.     sdbout_end_epilogue ();
  499. #endif
  500.  
  501.   /* If FUNCTION_EPILOGUE is not defined, then the function body
  502.      itself contains return instructions wherever needed.  */
  503. }
  504.  
  505. /* Output assembler code for some insns: all or part of a function.
  506.    For description of args, see `final_start_function', above.
  507.  
  508.    PRESCAN is 1 if we are not really outputting,
  509.      just scanning as if we were outputting.
  510.    Prescanning deletes and rearranges insns just like ordinary output.
  511.    PRESCAN is -2 if we are outputting after having prescanned.
  512.    In this case, don't try to delete or rearrange insns
  513.    because that has already been done.
  514.    Prescanning is done only on certain machines.  */
  515.  
  516. void
  517. final (first, file, write_symbols, optimize, prescan)
  518.      rtx first;
  519.      FILE *file;
  520.      enum debugger write_symbols;
  521.      int optimize;
  522.      int prescan;
  523. {
  524.   register rtx insn;
  525.  
  526.   last_ignored_compare = 0;
  527.   new_block = 1;
  528.  
  529.   init_recog ();
  530.  
  531.   CC_STATUS_INIT;
  532.  
  533.   for (insn = NEXT_INSN (first); insn;)
  534.     insn = final_scan_insn (insn, file, write_symbols, optimize,
  535.                 prescan, 0);
  536. }
  537.  
  538. /* The final scan for one insn, INSN.
  539.    Args are same as in `final', except that INSN
  540.    is the insn being scanned.
  541.    Value returned is the next insn to be scanned.
  542.  
  543.    NOPEEPHOLES is the flag to disallow peephole processing (currently
  544.    used for within delayed branch sequence output).  */
  545.  
  546. rtx
  547. final_scan_insn  (insn, file, write_symbols, optimize, prescan, nopeepholes)
  548.      rtx insn;
  549.      FILE *file;
  550.      enum debugger write_symbols;
  551.      int optimize;
  552.      int prescan;
  553.      int nopeepholes;
  554. {
  555.   register int i;
  556.   switch (GET_CODE (insn))
  557.     {
  558.     case NOTE:
  559.       if (prescan > 0)
  560.     break;
  561.       if (write_symbols == NO_DEBUG)
  562.     break;
  563.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
  564.     {
  565. #ifdef SDB_DEBUGGING_INFO
  566.       if (write_symbols == SDB_DEBUG)
  567.         sdbout_begin_function (last_linenum);
  568. #endif
  569.       break;
  570.     }
  571.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
  572.       || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  573.     break;
  574.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  575.     break;            /* An insn that was "deleted" */
  576.       if (app_on)
  577.     {
  578.       fprintf (file, ASM_APP_OFF);
  579.       app_on = 0;
  580.     }
  581.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG)
  582.     {
  583.       /* Beginning of a symbol-block.  Assign it a sequence number
  584.          and push the number onto the stack PENDING_BLOCKS.  */
  585.  
  586.       if (block_depth == max_block_depth)
  587.         {
  588.           /* PENDING_BLOCKS is full; make it longer.  */
  589.           max_block_depth *= 2;
  590.           pending_blocks
  591.         = (int *) xrealloc (pending_blocks,
  592.                     max_block_depth * sizeof (int));
  593.         }
  594.       pending_blocks[block_depth++] = next_block_index;
  595.  
  596.       /* Output debugging info about the symbol-block beginning.  */
  597.  
  598. #ifdef SDB_DEBUGGING_INFO
  599.       if (write_symbols == SDB_DEBUG)
  600.         sdbout_begin_block (file, last_linenum, next_block_index);
  601. #endif
  602. #ifdef DBX_DEBUGGING_INFO
  603.       if (write_symbols == DBX_DEBUG)
  604.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBB", next_block_index);
  605. #endif
  606.       if (write_symbols == GDB_DEBUG)
  607.         fprintf (file, "\t.gdbbeg %d\n", next_block_index);
  608.  
  609.       next_block_index++;
  610.     }
  611.       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
  612.     {
  613.       /* End of a symbol-block.  Pop its sequence number off
  614.          PENDING_BLOCKS and output debugging info based on that.  */
  615.  
  616.       --block_depth;
  617.  
  618. #ifdef DBX_DEBUGGING_INFO
  619.       if (write_symbols == DBX_DEBUG && block_depth >= 0)
  620.         ASM_OUTPUT_INTERNAL_LABEL (file, "LBE",
  621.                        pending_blocks[block_depth]);
  622. #endif
  623.  
  624. #ifdef SDB_DEBUGGING_INFO
  625.       if (write_symbols == SDB_DEBUG && block_depth >= 0)
  626.         sdbout_end_block (file, last_linenum);
  627. #endif
  628.  
  629.       if (write_symbols == GDB_DEBUG)
  630.         fprintf (file, "\t.gdbend %d\n", pending_blocks[block_depth]);
  631.     }
  632.       else if (NOTE_LINE_NUMBER (insn) > 0)
  633.     /* This note is a line-number.  */
  634.     output_source_line (file, insn, write_symbols);
  635.       break;
  636.  
  637.     case BARRIER:
  638. #ifdef ASM_OUTPUT_ALIGN_CODE
  639.       ASM_OUTPUT_ALIGN_CODE (file);
  640. #endif
  641.       break;
  642.  
  643.     case CODE_LABEL:
  644.       CC_STATUS_INIT;
  645.       if (prescan > 0)
  646.     break;
  647.       new_block = 1;
  648.       if (app_on)
  649.     {
  650.       fprintf (file, ASM_APP_OFF);
  651.       app_on = 0;
  652.     }
  653. #ifdef ASM_OUTPUT_CASE_LABEL
  654.       if (NEXT_INSN (insn) != 0
  655.       && GET_CODE (NEXT_INSN (insn)) == JUMP_INSN)
  656.     {
  657.       rtx nextbody = PATTERN (NEXT_INSN (insn));
  658.  
  659.       /* If this label is followed by a jump-table,
  660.          output the two of them together in a special way.  */
  661.  
  662.       if (GET_CODE (nextbody) == ADDR_VEC
  663.           || GET_CODE (nextbody) == ADDR_DIFF_VEC)
  664.         {
  665.           ASM_OUTPUT_CASE_LABEL (file, "L", CODE_LABEL_NUMBER (insn),
  666.                      NEXT_INSN (insn));
  667.           break;
  668.         }
  669.     }
  670. #endif
  671.  
  672.       ASM_OUTPUT_INTERNAL_LABEL (file, "L", CODE_LABEL_NUMBER (insn));
  673.       break;
  674.  
  675.     default:
  676.       {
  677.     register rtx body = PATTERN (insn);
  678.     int insn_code_number;
  679.     char *template;
  680.  
  681.     /* An INSN, JUMP_INSN or CALL_INSN.
  682.        First check for special kinds that recog doesn't recognize.  */
  683.  
  684.     if (GET_CODE (body) == USE /* These are just declarations */
  685.         || GET_CODE (body) == CLOBBER)
  686.       break;
  687.  
  688.     if (profile_block_flag && new_block)
  689.       {
  690.         new_block = 0;
  691.         /* Enable the table of basic-block use counts
  692.            to point at the code it applies to.  */
  693.         ASM_OUTPUT_INTERNAL_LABEL (file, "LPB", count_basic_blocks);
  694.         /* Before first insn of this basic block, increment the
  695.            count of times it was entered.  */
  696. #ifdef BLOCK_PROFILER
  697.         BLOCK_PROFILER (file, count_basic_blocks);
  698. #endif
  699.         count_basic_blocks++;
  700.       }
  701.  
  702.     if (GET_CODE (body) == ASM_INPUT)
  703.       {
  704.         /* There's no telling what that did to the condition codes.  */
  705.         CC_STATUS_INIT;
  706.         if (prescan > 0)
  707.           break;
  708.         if (! app_on)
  709.           {
  710.         fprintf (file, ASM_APP_ON);
  711.         app_on = 1;
  712.           }
  713.         fprintf (asm_out_file, "\t%s\n", XSTR (body, 0));
  714.         break;
  715.       }
  716.  
  717.     /* Detect `asm' construct with operands.  */
  718.     if (asm_noperands (body) >= 0)
  719.       {
  720.         int noperands = asm_noperands (body);
  721.         rtx *ops;
  722.         char *string;
  723.  
  724.         /* There's no telling what that did to the condition codes.  */
  725.         CC_STATUS_INIT;
  726.         if (prescan > 0)
  727.           break;
  728.  
  729.         /* alloca won't do here, since only return from `final'
  730.            would free it.  */
  731.         if (noperands > 0)
  732.           ops = (rtx *) xmalloc (noperands * sizeof (rtx));
  733.  
  734.         if (! app_on)
  735.           {
  736.         fprintf (file, ASM_APP_ON);
  737.         app_on = 1;
  738.           }
  739.  
  740.         /* Get out the operand values.  */
  741.         string = decode_asm_operands (body, ops, 0, 0, 0);
  742.         /* Inhibit aborts on what would otherwise be compiler bugs.  */
  743.         insn_noperands = noperands;
  744.         this_is_asm_operands = insn;
  745.         /* Output the insn using them.  */
  746.         output_asm_insn (string, ops);
  747.         this_is_asm_operands = 0;
  748.         if (noperands > 0)
  749.           free (ops);
  750.         break;
  751.       }
  752.  
  753.     if (prescan <= 0 && app_on)
  754.       {
  755.         fprintf (file, ASM_APP_OFF);
  756.         app_on = 0;
  757.       }
  758.  
  759.     /* Detect insns that are really jump-tables
  760.        and output them as such.  */
  761.  
  762.     if (GET_CODE (body) == ADDR_VEC)
  763.       {
  764.         register int vlen, idx;
  765.  
  766.         if (prescan > 0)
  767.           break;
  768.  
  769.         vlen = XVECLEN (body, 0);
  770.         for (idx = 0; idx < vlen; idx++)
  771.           ASM_OUTPUT_ADDR_VEC_ELT (file,
  772.                        CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
  773. #ifdef ASM_OUTPUT_CASE_END
  774.         ASM_OUTPUT_CASE_END (file,
  775.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  776.                  insn);
  777. #endif
  778.         break;
  779.       }
  780.     if (GET_CODE (body) == ADDR_DIFF_VEC)
  781.       {
  782.         register int vlen, idx;
  783.  
  784.         if (prescan > 0)
  785.           break;
  786.  
  787.         vlen = XVECLEN (body, 1);
  788.         for (idx = 0; idx < vlen; idx++)
  789.           ASM_OUTPUT_ADDR_DIFF_ELT (file,
  790.                     CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 1, idx), 0)),
  791.                     CODE_LABEL_NUMBER (XEXP (XEXP (body, 0), 0)));
  792. #ifdef ASM_OUTPUT_CASE_END
  793.         ASM_OUTPUT_CASE_END (file,
  794.                  CODE_LABEL_NUMBER (PREV_INSN (insn)),
  795.                  insn);
  796. #endif
  797.         break;
  798.       }
  799.  
  800.     if (recog_memoized (insn) == -1
  801.         && GET_CODE (body) == SEQUENCE) /* A delayed-branch sequence */
  802.       {
  803.         register int i;
  804.         if (prescan > 0)
  805.           break;
  806.         final_sequence = body;
  807.         for (i = 0; i < XVECLEN (body, 0); i++)
  808.           final_scan_insn (XVECEXP (body, 0, i), file, write_symbols,
  809.                    optimize, prescan, 1);
  810.         final_sequence = 0;
  811. #ifdef DBR_OUTPUT_SEQEND
  812.         DBR_OUTPUT_SEQEND (file);
  813. #endif
  814.         break;
  815.       }
  816.  
  817.     /* We have a real machine instruction as rtl.  */
  818.  
  819.     body = PATTERN (insn);
  820.  
  821.     /* Check for redundant test and compare instructions
  822.        (when the condition codes are already set up as desired).
  823.        This is done only when optimizing; if not optimizing,
  824.        it should be possible for the user to alter a variable
  825.        with the debugger in between statements
  826.        and the next statement should reexamine the variable
  827.        to compute the condition codes.  */
  828.  
  829.     if (optimize
  830.         && GET_CODE (body) == SET
  831.         && GET_CODE (SET_DEST (body)) == CC0
  832.         && insn != last_ignored_compare)
  833.       {
  834.         if (GET_CODE (SET_SRC (body)) == SUBREG)
  835.           SET_SRC (body) = alter_subreg (SET_SRC (body));
  836.         if ((cc_status.value1 != 0
  837.          && rtx_equal_p (SET_SRC (body), cc_status.value1))
  838.         || (cc_status.value2 != 0
  839.             && rtx_equal_p (SET_SRC (body), cc_status.value2)))
  840.           {
  841.         /* Don't delete insn if has an addressing side-effect */
  842.         if (! find_reg_note (insn, REG_INC, 0)
  843.             /* or if anything in it is volatile.  */
  844.             && ! volatile_refs_p (PATTERN (insn)))
  845.           {
  846.             /* We don't really delete the insn; just ignore it.  */
  847.             last_ignored_compare = insn;
  848.             break;
  849.           }
  850.           }
  851.       }
  852.  
  853.     /* Following a conditional branch, we have a new basic block.  */
  854.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (body) == SET
  855.         && GET_CODE (SET_SRC (body)) != LABEL_REF)
  856.       new_block = 1;
  857.  
  858.     /* If this is a conditional branch, maybe modify it
  859.        if the cc's are in a nonstandard state
  860.        so that it accomplishes the same thing that it would
  861.        do straightforwardly if the cc's were set up normally.  */
  862.  
  863.     if (cc_status.flags != 0
  864.         && GET_CODE (insn) == JUMP_INSN
  865.         && GET_CODE (body) == SET
  866.         && SET_DEST (body) == pc_rtx
  867.         && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE
  868.         /* This is done during prescan; it is not done again
  869.            in final scan when prescan has been done.  */
  870.         && prescan >= 0)
  871.       {
  872.         /* This function may alter the contents of its argument
  873.            and clear some of the cc_status.flags bits.
  874.            It may also return 1 meaning condition now always true
  875.            or -1 meaning condition now always false
  876.            or 2 meaning condition nontrivial but altered.  */
  877.         register int result = alter_cond (XEXP (SET_SRC (body), 0));
  878.         /* If condition now has fixed value, replace the IF_THEN_ELSE
  879.            with its then-operand or its else-operand.  */
  880.         if (result == 1)
  881.           SET_SRC (body) = XEXP (SET_SRC (body), 1);
  882.         if (result == -1)
  883.           SET_SRC (body) = XEXP (SET_SRC (body), 2);
  884.         /* The jump is now either unconditional or a no-op.
  885.            If it has become a no-op, don't try to output it.
  886.            (It would not be recognized.)  */
  887.         if (SET_SRC (body) == pc_rtx)
  888.           {
  889.         PUT_CODE (insn, NOTE);
  890.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  891.         NOTE_SOURCE_FILE (insn) = 0;
  892.         break;
  893.           }
  894.         /* Rerecognize the instruction if it has changed.  */
  895.         if (result != 0)
  896.           INSN_CODE (insn) = -1;
  897.       }
  898.  
  899. #ifdef STORE_FLAG_VALUE
  900.     /* Make same adjustments to instructions that examine the
  901.        condition codes without jumping (if this machine has them).  */
  902.  
  903.     if (cc_status.flags != 0
  904.         && GET_CODE (body) == SET)
  905.       switch (GET_CODE (SET_SRC (body)))
  906.         {
  907.         case GTU:
  908.         case GT:
  909.         case LTU:
  910.         case LT:
  911.         case GEU:
  912.         case GE:
  913.         case LEU:
  914.         case LE:
  915.         case EQ:
  916.         case NE:
  917.           {
  918.         register int result;
  919.         if (GET_CODE (XEXP (SET_SRC (body), 0)) != CC0)
  920.           break;
  921.         result = alter_cond (SET_SRC (body));
  922.         if (result == 1)
  923.           SET_SRC (body) = gen_rtx (CONST_INT, VOIDmode,
  924.                         STORE_FLAG_VALUE);
  925.         if (result == -1)
  926.           SET_SRC (body) = const0_rtx;
  927.         if (result != 0)
  928.           INSN_CODE (insn) = -1;
  929.           }
  930.         }
  931. #endif                /* STORE_FLAG_VALUE */
  932.  
  933.     /* Do machine-specific peephole optimizations if desired.  */
  934.  
  935.     if (optimize && !flag_no_peephole && !nopeepholes)
  936.       {
  937.         rtx next = peephole (insn);
  938.         /* When peepholing, if there were notes within the peephole,
  939.            emit them before the peephole.  */
  940.         if (next != 0 && next != NEXT_INSN (insn))
  941.           {
  942.         rtx note = NEXT_INSN (insn);
  943.         rtx prev = PREV_INSN (insn);
  944.         while (note != next)
  945.           {
  946.             final_scan_insn (note, file, write_symbols, optimize,
  947.                      prescan, nopeepholes);
  948.             note = NEXT_INSN (note);
  949.           }
  950.         /* In case this is prescan, put the notes
  951.            in proper position for later rescan.  */
  952.         note = NEXT_INSN (insn);
  953.         PREV_INSN (note) = prev;
  954.         NEXT_INSN (prev) = note;
  955.         NEXT_INSN (PREV_INSN (next)) = insn;
  956.         PREV_INSN (insn) = PREV_INSN (next);
  957.         NEXT_INSN (insn) = next;
  958.         PREV_INSN (next) = insn;
  959.           }
  960.  
  961.         /* PEEPHOLE might have changed this.  */
  962.         body = PATTERN (insn);
  963.       }
  964.  
  965.     /* Try to recognize the instruction.
  966.        If successful, verify that the operands satisfy the
  967.        constraints for the instruction.  Crash if they don't,
  968.        since `reload' should have changed them so that they do.  */
  969.  
  970.     insn_code_number = recog_memoized (insn);
  971.     insn_extract (insn);
  972.     for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  973.       {
  974.         if (GET_CODE (recog_operand[i]) == SUBREG)
  975.           recog_operand[i] = alter_subreg (recog_operand[i]);
  976.       }
  977.  
  978. #ifdef REGISTER_CONSTRAINTS
  979.     if (! constrain_operands (insn_code_number))
  980.       abort ();
  981. #endif
  982.  
  983.     /* Some target machines need to prescan each insn before
  984.        it is output.  */
  985.  
  986. #ifdef FINAL_PRESCAN_INSN
  987.     FINAL_PRESCAN_INSN (insn, recog_operand,
  988.                 insn_n_operands[insn_code_number]);
  989. #endif
  990.  
  991.     cc_prev_status = cc_status;
  992.  
  993.     /* Update `cc_status' for this instruction.
  994.        The instruction's output routine may change it further.
  995.        If the output routine for a jump insn needs to depend
  996.        on the cc status, it should look at cc_prev_status.  */
  997.  
  998.     NOTICE_UPDATE_CC (body, insn);
  999.  
  1000.     /* If the proper template needs to be chosen by some C code,
  1001.        run that code and get the real template.  */
  1002.  
  1003.     template = insn_template[insn_code_number];
  1004.     if (template == 0)
  1005.       {
  1006.         template = (*insn_outfun[insn_code_number]) (recog_operand, insn);
  1007.  
  1008.         /* If the C code returns 0, it means that it is a jump insn
  1009.            which follows a deleted test insn, and that test insn
  1010.            needs to be reinserted.  */
  1011.         if (template == 0)
  1012.           {
  1013.         if (PREV_INSN (insn) != last_ignored_compare)
  1014.           abort ();
  1015.         new_block = 0;
  1016.         return PREV_INSN (insn);
  1017.           }
  1018.       }
  1019.  
  1020.     if (prescan > 0)
  1021.       break;
  1022.  
  1023.     /* Output assembler code from the template.  */
  1024.  
  1025.     output_asm_insn (template, recog_operand);
  1026.  
  1027.     /* Mark this insn as having been output.  */
  1028.     INSN_DELETED_P (insn) = 1;
  1029.       }
  1030.     }
  1031.   return NEXT_INSN (insn);
  1032. }
  1033.  
  1034. /* Set up FILENAME as the current file for GDB line-number output.  */
  1035.  
  1036. void
  1037. set_current_gdbfile (filename)
  1038.      char *filename;
  1039. {
  1040.   register struct gdbfile *f;
  1041.   for (f = gdbfiles; f; f = f->next)
  1042.     if (!strcmp (f->name, filename))
  1043.       break;
  1044.  
  1045.   if (!f)
  1046.     {
  1047.       f = (struct gdbfile *) permalloc (sizeof (struct gdbfile));
  1048.       f->next = gdbfiles;
  1049.       gdbfiles = f;
  1050.       f->name = filename;
  1051.       f->filenum = next_gdb_filenum++;
  1052.       f->nlines = 0;
  1053.     }
  1054.   current_gdbfile = f;
  1055.   lastfile = filename;
  1056. }
  1057.  
  1058. /* Output debugging info to the assembler file FILE
  1059.    based on the NOTE-insn INSN, assumed to be a line number.  */
  1060.  
  1061. static void
  1062. output_source_line (file, insn, write_symbols)
  1063.      FILE *file;
  1064.      rtx insn;
  1065.      enum debugger write_symbols;
  1066. {
  1067.   register char *filename = NOTE_SOURCE_FILE (insn);
  1068.  
  1069.   last_linenum = NOTE_LINE_NUMBER (insn);
  1070.  
  1071.   if (write_symbols == GDB_DEBUG)
  1072.     {
  1073.       /* Output GDB-format line number info.  */
  1074.  
  1075.       /* If this is not the same source file as last time,
  1076.      find or assign a GDB-file-number to this file.  */
  1077.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)
  1078.                || current_gdbfile == 0))
  1079.     set_current_gdbfile (filename);
  1080.  
  1081.       ++current_gdbfile->nlines;
  1082.       fprintf (file, "\t.gdbline %d,%d\n",
  1083.            current_gdbfile->filenum, NOTE_LINE_NUMBER (insn));
  1084.     }
  1085.  
  1086.   if (write_symbols == SDB_DEBUG || write_symbols == DBX_DEBUG)
  1087.     {
  1088. #ifdef SDB_DEBUGGING_INFO
  1089.       if (write_symbols == SDB_DEBUG
  1090. #if 0 /* People like having line numbers even in wrong file!  */
  1091.       /* COFF can't handle multiple source files--lose, lose.  */
  1092.       && !strcmp (filename, main_input_filename)
  1093. #endif
  1094.       /* COFF relative line numbers must be positive.  */
  1095.       && last_linenum > sdb_begin_function_line)
  1096.     {
  1097. #ifdef ASM_OUTPUT_SOURCE_LINE
  1098.       ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  1099. #else
  1100.       fprintf (file, "\t.ln\t%d\n",
  1101.            (sdb_begin_function_line
  1102.             ? last_linenum - sdb_begin_function_line : 1));
  1103. #endif
  1104.     }
  1105. #endif
  1106.  
  1107. #ifdef DBX_DEBUGGING_INFO
  1108.       if (write_symbols == DBX_DEBUG)
  1109.     {
  1110.       /* Write DBX line number data.  */
  1111.  
  1112.       if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
  1113.         {
  1114. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  1115.           ASM_OUTPUT_SOURCE_FILENAME (file, filename);
  1116. #else
  1117.           fprintf (file, "\t.stabs \"%s\",%d,0,0,Ltext\n",
  1118.                filename, N_SOL);
  1119. #endif
  1120.           lastfile = filename;
  1121.         }
  1122.     }
  1123.  
  1124. #ifdef ASM_OUTPUT_SOURCE_LINE
  1125.       ASM_OUTPUT_SOURCE_LINE (file, NOTE_LINE_NUMBER (insn));
  1126. #else
  1127.       fprintf (file, "\t.stabd %d,0,%d\n",
  1128.            N_SLINE, NOTE_LINE_NUMBER (insn));
  1129. #endif
  1130. #endif /* DBX_DEBUGGING_INFO */
  1131.     }
  1132. }
  1133.  
  1134. /* If X is a SUBREG, replace it with a REG or a MEM,
  1135.    based on the thing it is a subreg of.  */
  1136.  
  1137. rtx
  1138. alter_subreg (x)
  1139.      register rtx x;
  1140. {
  1141.   register rtx y = SUBREG_REG (x);
  1142.   if (GET_CODE (y) == SUBREG)
  1143.     y = alter_subreg (y);
  1144.  
  1145.   if (GET_CODE (y) == REG)
  1146.     {
  1147.       /* If the containing reg really gets a hard reg, so do we.  */
  1148.       PUT_CODE (x, REG);
  1149.       REGNO (x) = REGNO (y) + SUBREG_WORD (x);
  1150.     }
  1151.   else if (GET_CODE (y) == MEM)
  1152.     {
  1153.       register int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1154. #ifdef BYTES_BIG_ENDIAN
  1155.       offset -= (min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x)))
  1156.          - min (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (y))));
  1157. #endif
  1158.       PUT_CODE (x, MEM);
  1159.       MEM_VOLATILE_P (x) = MEM_VOLATILE_P (y);
  1160.       XEXP (x, 0) = plus_constant (XEXP (y, 0), offset);
  1161.     }
  1162.   else if (GET_CODE (y) == CONST_DOUBLE)
  1163.     return y;
  1164.  
  1165.   return x;
  1166. }
  1167.  
  1168. /* Do alter_subreg on all the SUBREGs contained in X.  */
  1169.  
  1170. static rtx
  1171. walk_alter_subreg (x)
  1172.      rtx x;
  1173. {
  1174.   switch (GET_CODE (x))
  1175.     {
  1176.     case PLUS:
  1177.     case MULT:
  1178.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1179.       XEXP (x, 1) = walk_alter_subreg (XEXP (x, 1));
  1180.       break;
  1181.  
  1182.     case MEM:
  1183.       XEXP (x, 0) = walk_alter_subreg (XEXP (x, 0));
  1184.       break;
  1185.  
  1186.     case SUBREG:
  1187.       return alter_subreg (x);
  1188.     }
  1189.  
  1190.   return x;
  1191. }
  1192.  
  1193. /* Given BODY, the body of a jump instruction, alter the jump condition
  1194.    as required by the bits that are set in cc_status.flags.
  1195.    Not all of the bits there can be handled at this level in all cases.
  1196.  
  1197.    The value is normally 0.
  1198.    1 means that the condition has become always true.
  1199.    -1 means that the condition has become always false.
  1200.    2 means that COND has been altered.  */
  1201.  
  1202. static int
  1203. alter_cond (cond)
  1204.      register rtx cond;
  1205. {
  1206.   int value = 0;
  1207.  
  1208.   if (cc_status.flags & CC_REVERSED)
  1209.     {
  1210.       value = 2;
  1211.       switch (GET_CODE (cond))
  1212.     {
  1213.     case LE:
  1214.       PUT_CODE (cond, GE);
  1215.       break;
  1216.     case GE:
  1217.       PUT_CODE (cond, LE);
  1218.       break;
  1219.     case LT:
  1220.       PUT_CODE (cond, GT);
  1221.       break;
  1222.     case GT:
  1223.       PUT_CODE (cond, LT);
  1224.       break;
  1225.     case LEU:
  1226.       PUT_CODE (cond, GEU);
  1227.       break;
  1228.     case GEU:
  1229.       PUT_CODE (cond, LEU);
  1230.       break;
  1231.     case LTU:
  1232.       PUT_CODE (cond, GTU);
  1233.       break;
  1234.     case GTU:
  1235.       PUT_CODE (cond, LTU);
  1236.       break;
  1237.     }
  1238.     }
  1239.  
  1240.   if (cc_status.flags & CC_NOT_POSITIVE)
  1241.     switch (GET_CODE (cond))
  1242.       {
  1243.       case LE:
  1244.       case LEU:
  1245.       case GEU:
  1246.     /* Jump becomes unconditional.  */
  1247.     return 1;
  1248.  
  1249.       case GT:
  1250.       case GTU:
  1251.       case LTU:
  1252.     /* Jump becomes no-op.  */
  1253.     return -1;
  1254.  
  1255.       case GE:
  1256.     PUT_CODE (cond, EQ);
  1257.     value = 2;
  1258.     break;
  1259.  
  1260.       case LT:
  1261.     PUT_CODE (cond, NE);
  1262.     value = 2;
  1263.     break;
  1264.       }
  1265.  
  1266.   if (cc_status.flags & CC_NOT_NEGATIVE)
  1267.     switch (GET_CODE (cond))
  1268.       {
  1269.       case GE:
  1270.       case GEU:
  1271.     /* Jump becomes unconditional.  */
  1272.     return 1;
  1273.  
  1274.       case LT:
  1275.       case LTU:
  1276.     /* Jump becomes no-op.  */
  1277.     return -1;
  1278.  
  1279.       case LE:
  1280.       case LEU:
  1281.     PUT_CODE (cond, EQ);
  1282.     value = 2;
  1283.     break;
  1284.  
  1285.       case GT:
  1286.       case GTU:
  1287.     PUT_CODE (cond, NE);
  1288.     value = 2;
  1289.     break;
  1290.       }
  1291.  
  1292.   if (cc_status.flags & CC_NO_OVERFLOW)
  1293.     switch (GET_CODE (cond))
  1294.       {
  1295.       case GEU:
  1296.     /* Jump becomes unconditional.  */
  1297.     return 1;
  1298.  
  1299.       case LEU:
  1300.     PUT_CODE (cond, EQ);
  1301.     value = 2;
  1302.     break;
  1303.  
  1304.       case GTU:
  1305.     PUT_CODE (cond, NE);
  1306.     value = 2;
  1307.     break;
  1308.  
  1309.       case LTU:
  1310.     /* Jump becomes no-op.  */
  1311.     return -1;
  1312.       }
  1313.  
  1314.   if (cc_status.flags & (CC_Z_IN_NOT_N | CC_Z_IN_N))
  1315.     switch (GET_CODE (cond))
  1316.       {
  1317.       case LE:
  1318.       case LEU:
  1319.       case GE:
  1320.       case GEU:
  1321.       case LT:
  1322.       case LTU:
  1323.       case GT:
  1324.       case GTU:
  1325.     abort ();
  1326.  
  1327.       case NE:
  1328.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? GE : LT);
  1329.     value = 2;
  1330.     break;
  1331.  
  1332.       case EQ:
  1333.     PUT_CODE (cond, cc_status.flags & CC_Z_IN_N ? LT : GE);
  1334.     value = 2;
  1335.     break;
  1336.       }
  1337.   
  1338.   return value;
  1339. }
  1340.  
  1341. /* Report inconsistency between the assembler template and the operands.
  1342.    In an `asm', it's the user's fault; otherwise, the compiler's fault.  */
  1343.  
  1344. static void
  1345. output_operand_lossage (str)
  1346.      char *str;
  1347. {
  1348.   if (this_is_asm_operands)
  1349.     error_for_asm (this_is_asm_operands, "invalid `asm': %s", str);
  1350.   else
  1351.     abort ();
  1352. }
  1353.  
  1354. /* Output of assembler code from a template, and its subroutines.  */
  1355.  
  1356. /* Output text from TEMPLATE to the assembler output file,
  1357.    obeying %-directions to substitute operands taken from
  1358.    the vector OPERANDS.
  1359.  
  1360.    %N (for N a digit) means print operand N in usual manner.
  1361.    %lN means require operand N to be a CODE_LABEL or LABEL_REF
  1362.       and print the label name with no punctuation.
  1363.    %cN means require operand N to be a constant
  1364.       and print the constant expression with no punctuation.
  1365.    %aN means expect operand N to be a memory address
  1366.       (not a memory reference!) and print a reference
  1367.       to that address.
  1368.    %nN means expect operand N to be a constant
  1369.       and print a constant expression for minus the value
  1370.       of the operand, with no other punctuation.  */
  1371.  
  1372. void
  1373. output_asm_insn (template, operands)
  1374.      char *template;
  1375.      rtx *operands;
  1376. {
  1377.   register char *p;
  1378.   register int c;
  1379.  
  1380.   /* An insn may return a null string template
  1381.      in a case where no assembler code is needed.  */
  1382.   if (*template == 0)
  1383.     return;
  1384.  
  1385.   p = template;
  1386.   putc ('\t', asm_out_file);
  1387.  
  1388. #ifdef ASM_OUTPUT_OPCODE
  1389.   ASM_OUTPUT_OPCODE (asm_out_file, p);
  1390. #endif
  1391.  
  1392.   while (c = *p++)
  1393.     {
  1394. #ifdef ASM_OUTPUT_OPCODE
  1395.       if (c == '\n')
  1396.     {
  1397.       putc (c, asm_out_file);
  1398.       while ((c = *p) == '\t')
  1399.         {
  1400.           putc (c, asm_out_file);
  1401.           p++;
  1402.         }
  1403.       ASM_OUTPUT_OPCODE (asm_out_file, p);
  1404.     }
  1405.       else
  1406. #endif
  1407.       if (c != '%')
  1408.     putc (c, asm_out_file);
  1409.       else
  1410.     {
  1411.       /* %% outputs a single %.  */
  1412.       if (*p == '%')
  1413.         {
  1414.           p++;
  1415.           putc (c, asm_out_file);
  1416.         }
  1417.       /* % followed by a letter and some digits
  1418.          outputs an operand in a special way depending on the letter.
  1419.          Letters `acln' are implemented here.
  1420.          Other letters are passed to `output_operand' so that
  1421.          the PRINT_OPERAND macro can define them.  */
  1422.       else if ((*p >= 'a' && *p <= 'z')
  1423.            || (*p >= 'A' && *p <= 'Z'))
  1424.         {
  1425.           int letter = *p++;
  1426.           c = atoi (p);
  1427.  
  1428.           if (! (*p >= '0' && *p <= '9'))
  1429.         output_operand_lossage ("operand number missing after %-letter");
  1430.           else if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1431.         output_operand_lossage ("operand number out of range");
  1432.           else if (letter == 'l')
  1433.         output_asm_label (operands[c]);
  1434.           else if (letter == 'a')
  1435.         output_address (operands[c]);
  1436.           else if (letter == 'c')
  1437.         {
  1438.           if (CONSTANT_ADDRESS_P (operands[c]))
  1439.             output_addr_const (asm_out_file, operands[c]);
  1440.           else
  1441.             output_operand (operands[c], 'c');
  1442.         }
  1443.           else if (letter == 'n')
  1444.         {
  1445.           if (GET_CODE (operands[c]) == CONST_INT)
  1446.             fprintf (asm_out_file, "%d", - INTVAL (operands[c]));
  1447.           else
  1448.             {
  1449.               putc ('-', asm_out_file);
  1450.               output_addr_const (asm_out_file, operands[c]);
  1451.             }
  1452.         }
  1453.           else
  1454.         output_operand (operands[c], letter);
  1455.  
  1456.           while ((c = *p) >= '0' && c <= '9') p++;
  1457.         }
  1458.       /* % followed by a digit outputs an operand the default way.  */
  1459.       else if (*p >= '0' && *p <= '9')
  1460.         {
  1461.           c = atoi (p);
  1462.           if (this_is_asm_operands && c >= (unsigned) insn_noperands)
  1463.         output_operand_lossage ("operand number out of range");
  1464.           else
  1465.         output_operand (operands[c], 0);
  1466.           while ((c = *p) >= '0' && c <= '9') p++;
  1467.         }
  1468.       /* % followed by punctuation: output something for that
  1469.          punctuation character alone, with no operand.
  1470.          The PRINT_OPERAND macro decides what is actually done.  */
  1471. #ifdef PRINT_OPERAND_PUNCT_VALID_P
  1472.       else if (PRINT_OPERAND_PUNCT_VALID_P (*p))
  1473.         output_operand (0, *p++);
  1474. #endif
  1475.       else
  1476.         output_operand_lossage ("invalid %%-code");
  1477.     }
  1478.     }
  1479.  
  1480.   putc ('\n', asm_out_file);
  1481. }
  1482.  
  1483. /* Output a LABEL_REF, or a bare CODE_LABEL, as an assembler symbol.  */
  1484.  
  1485. void
  1486. output_asm_label (x)
  1487.      rtx x;
  1488. {
  1489.   char buf[256];
  1490.  
  1491.   if (GET_CODE (x) == LABEL_REF)
  1492.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1493.   else if (GET_CODE (x) == CODE_LABEL)
  1494.     ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1495.   else
  1496.     output_operand_lossage ("`%l' operand isn't a label");
  1497.  
  1498.   assemble_name (asm_out_file, buf);
  1499. }
  1500.  
  1501. /* Print operand X using machine-dependent assembler syntax.
  1502.    The macro PRINT_OPERAND is defined just to control this function.
  1503.    CODE is a non-digit that preceded the operand-number in the % spec,
  1504.    such as 'z' if the spec was `%z3'.  CODE is 0 if there was no char
  1505.    between the % and the digits.
  1506.    When CODE is a non-letter, X is 0.
  1507.  
  1508.    The meanings of the letters are machine-dependent and controlled
  1509.    by PRINT_OPERAND.  */
  1510.  
  1511. static void
  1512. output_operand (x, code)
  1513.      rtx x;
  1514.      int code;
  1515. {
  1516.   if (x && GET_CODE (x) == SUBREG)
  1517.     x = alter_subreg (x);
  1518.   PRINT_OPERAND (asm_out_file, x, code);
  1519. }
  1520.  
  1521. /* Print a memory reference operand for address X
  1522.    using machine-dependent assembler syntax.
  1523.    The macro PRINT_OPERAND_ADDRESS exists just to control this function.  */
  1524.  
  1525. void
  1526. output_address (x)
  1527.      rtx x;
  1528. {
  1529.   walk_alter_subreg (x);
  1530.   PRINT_OPERAND_ADDRESS (asm_out_file, x);
  1531. }
  1532.  
  1533. /* Print an integer constant expression in assembler syntax.
  1534.    Addition and subtraction are the only arithmetic
  1535.    that may appear in these expressions.  */
  1536.  
  1537. void
  1538. output_addr_const (file, x)
  1539.      FILE *file;
  1540.      rtx x;
  1541. {
  1542.   char buf[256];
  1543.  
  1544.  restart:
  1545.   switch (GET_CODE (x))
  1546.     {
  1547.     case SYMBOL_REF:
  1548.       assemble_name (file, XSTR (x, 0));
  1549.       break;
  1550.  
  1551.     case LABEL_REF:
  1552.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
  1553.       assemble_name (asm_out_file, buf);
  1554.       break;
  1555.  
  1556.     case CODE_LABEL:
  1557.       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
  1558.       assemble_name (asm_out_file, buf);
  1559.       break;
  1560.  
  1561.     case CONST_INT:
  1562.       fprintf (file, "%d", INTVAL (x));
  1563.       break;
  1564.  
  1565.     case CONST:
  1566.       x = XEXP (x, 0);
  1567.       goto restart;
  1568.  
  1569.     case CONST_DOUBLE:
  1570.       if (GET_MODE (x) == DImode)
  1571.     {
  1572.       /* We can use %d if the number is <32 bits and positive.  */
  1573.       if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
  1574.         fprintf (file, "0x%x%08x",
  1575.              CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
  1576.       else
  1577.         fprintf (file, "%d", CONST_DOUBLE_LOW (x));
  1578.     }
  1579.       else
  1580.     /* We can't handle floating point constants;
  1581.        PRINT_OPERAND must handle them.  */
  1582.     output_operand_lossage ("floating constant misused");
  1583.       break;
  1584.  
  1585.     case PLUS:
  1586.       /* Some assemblers need integer constants to appear last (eg masm).  */
  1587.       if (GET_CODE (XEXP (x, 0)) == CONST_INT)
  1588.     {
  1589.       output_addr_const (file, XEXP (x, 1));
  1590.       if (INTVAL (XEXP (x, 0)) >= 0)
  1591.         fprintf (file, "+");
  1592.       output_addr_const (file, XEXP (x, 0));
  1593.     }
  1594.       else
  1595.     {
  1596.       output_addr_const (file, XEXP (x, 0));
  1597.       if (INTVAL (XEXP (x, 1)) >= 0)
  1598.         fprintf (file, "+");
  1599.       output_addr_const (file, XEXP (x, 1));
  1600.     }
  1601.       break;
  1602.  
  1603.     case MINUS:
  1604.       output_addr_const (file, XEXP (x, 0));
  1605.       fprintf (file, "-");
  1606.       output_addr_const (file, XEXP (x, 1));
  1607.       break;
  1608.  
  1609.     default:
  1610.       output_operand_lossage ("invalid expression as operand");
  1611.     }
  1612. }
  1613.